class Solution {
public:
    bool check(unordered_map<char,int>& ump){
        for(pair<char,int> kv : ump){
            if(kv.second > 0){
                return false;
            }
        }
        return true;
    }
    
    string minWindow(string s, string t) {
        unordered_map<char,int> ump;
        for(char e : t){
            ump[e]++;
        }
        
        string ret = "";
        int i = 0;
        int j = 0;
        int sum = s.size();
        
        for(;j < s.size();j++){
            if(ump.find(s[j]) != ump.end()){
                ump[s[j]]--;
            }
            
            while(check(ump) == true){
                int len = j - i + 1;
                if(len <= sum){
                    sum = len;
                    ret = string(s.begin()+i,s.begin()+j+1);
                }
                
                if(t.find(s[i]) != t.npos){
                    ump[s[i]]++;
                }
                i++;
            }
        }
        return ret;
    }
};
